package cn.xyfmzmy.decorator.input;

import java.io.*;
import java.time.Instant;

public class Main {

    public static void main(String[] args) {
        File file = new File("test.jpg");
        long start = Instant.now().toEpochMilli();
        try(ReadCountFileInputStream inputStream = new ReadCountFileInputStream(new BufferedFileInputStream(new FileInputStream(file)))){
            while(true){
                int read = inputStream.read();
                if(read == -1){
                    break;
                }
            }
            System.out.println("用时:" + (Instant.now().toEpochMilli() - start) + "ms");
            System.out.println("调用过：" + inputStream.readCount() + "次read方法");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
